﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Naruto.TaskManagement.Application;
using Naruto.TaskManagement.Entitys.DTO;
using Naruto.TaskManagement.Infrastructure;

namespace Naruto.TaskManagement.WebApi.Controllers
{
    [Route("api/task")]
    [ApiController]
    public class TaskRecordController : ControllerBase
    {
        private readonly TaskRecordApps taskRecordApps;

        public TaskRecordController(TaskRecordApps _taskRecordApps)
        {
            taskRecordApps = _taskRecordApps;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public async Task<NarutoResult> Add(TaskRecordAddDTO info)
        {
            return await taskRecordApps.Add(info);
        }

        [HttpPost("update")]
        /// <summary>
        /// 修改
        /// </summary>
        /// <returns></returns>
        public async Task<NarutoResult> Update(TaskRecordAddDTO info) => await taskRecordApps.Update(info);
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        [HttpGet("list/{status}")]
        public async Task<NarutoResult> GetList([FromRoute] int status, [FromQuery] TaskRecordGetListDTO info) => await taskRecordApps.GetList(status, info);

        [HttpGet("{id}")]
        /// <summary>
        /// 根据id 获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<NarutoResult> GetById(string id) => await taskRecordApps.GetById(id);

        [HttpPut("{id}")]
        /// <summary>
        /// 更新状态
        /// </summary>
        /// <param name="id"></param>
        /// <param name="status"></param>
        /// <returns></returns>
        public async Task<NarutoResult> UpdateStatus(string id, UpdateStatusDTO info) => await taskRecordApps.UpdateStatus(id, info);
        [HttpDelete("{id}")]
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<NarutoResult> Delete(string id, TaskRecordDeleteDTO info) => await taskRecordApps.Delete(id, info);

        [HttpGet("my/{userName}")]
        /// <summary>
        /// 获取我的任务
        /// </summary>
        /// <param name="userName"></param>
        /// <returns></returns>
        public async Task<NarutoResult> GetMyTaskCount(string userName) => await taskRecordApps.GetMyTaskCount(userName);

        [HttpGet("count")]
        /// <summary>
        /// 获取数据总数
        /// </summary>
        /// <param name="title">标题</param>
        /// <param name="type"></param>
        /// <param name="userName">用户名</param>
        /// <param name="organizationId">组织id</param>
        /// <returns></returns>
        public async Task<NarutoResult> GetListCount([FromQuery] TaskRecordGetListDTO info) => await taskRecordApps.GetListCount(info);
    }
}
